package com.guigu.liuzhireng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuzhireng.mapper.MenuMapper;
import com.guigu.liuzhireng.pojo.Menu;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.liuzhireng.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    MenuMapper menuMapper;

    @Override
    public int update(Menu menu) {
        return menuMapper.updateByPrimaryKeySelective(menu);
    }

    @Override
    public int insert(Menu menu) {
        return menuMapper.insert(menu);
    }

    @Override
    public int delete(Integer id) {
        return menuMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageVo<Menu> Page(Menu menu, int num, int size) {
        PageHelper.startPage(num,size);
        List<Menu> list = menuMapper.MenuAll(menu);
        PageInfo<Menu> pageInfo = new PageInfo<>(list);
        PageVo<Menu> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }

    @Override
    public List<Menu> MenuAll() {
        return menuMapper.LIST();
    }
}
